package com.cf.data.serve.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping
@Slf4j
public class ShouChiKaoQinController {
    //init 初始化配置请求
    @RequestMapping(value = "/init", method = RequestMethod.GET)
    public JSONObject initcshpzqq(String deviceId, String productId, String mac, String porttype){
        System.out.println("初始化配置请求");
        JSONObject dgBaseInfo = new JSONObject();
        JSONObject setting = new JSONObject();
        JSONObject f = new JSONObject();
        f.put("success",true);
        f.put("code",0);
        f.put("message","success");
        f.put("time",String.valueOf(System.currentTimeMillis()));

        f.put("dgBaseInfo",dgBaseInfo);
        f.put("setting",setting);


        return f;
    }

    //下载白名单
    @RequestMapping(value = "/workers", method = RequestMethod.GET)
    public JSONObject xzbmd(String deviceId,String productId,int update){
        System.out.println("请求人员名单");
        JSONObject[] objects = new JSONObject[1];
        JSONObject ss = new JSONObject();
        JSONObject f = new JSONObject();
        f.put("success",true);
        f.put("code",0);
        f.put("message","success");
        f.put("time",update);
        //data人员列表内容
        //必填
        ss.put("name","测试");//人员姓名（必填）
        ss.put("workerId","1111111111");//人员编号（必填）
        ss.put("photo","http://60.210.113.222:9092/scheduling/static/upload/b1ad0692-91b3-4699-9b38-ec5b31f7af47_.jpg");//人员照片（必填）
        ss.put("update",String.valueOf(System.currentTimeMillis()));//最后更新时间（必填）
        ss.put("projectId","1");//项目id（必填）
        objects[0] = ss;
        f.put("data",objects);
        return f;
    }

    //考勤照片上传
    @RequestMapping(value = "/photo", method = RequestMethod.POST)
    public JSONObject kqzpsc(String ts, @RequestBody String tu){
        Map<String,Object> map;
        JSONObject[] objects = new JSONObject[]{};
        JSONObject f = new JSONObject();
        JSONObject ss = new JSONObject();
        f.put("success",true);
        f.put("code",0);
        f.put("message","success");
        f.put("time",String.valueOf(System.currentTimeMillis()));
        //data数据
        ss.put("path","");//图片地址

        f.put("data",ss);
        JSONObject jsonObject = JSON.parseObject(tu);
        map = jsonObject.getInnerMap();
        System.out.println("设备编号：");
        System.out.println(map.get("deviceId"));
        System.out.println("图片 base64 编码:");
        System.out.println(map.get("base64"));
        return f;
    }

    //下拉考勤区域
    @RequestMapping(value = "/area", method = RequestMethod.GET)
    public JSONObject xlkqqy(){
        JSONObject f = new JSONObject();

        return f;
    }
}
